package com.ssy.lingxi.purchase.controller.tender;

import cn.hutool.core.bean.BeanUtil;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.purchase.api.dto.response.tender.SubmitTenderOutCheckRecordResponse;
import com.ssy.lingxi.purchase.api.dto.response.tender.TenderOutCheckRecordResponse;
import com.ssy.lingxi.purchase.entity.tender.InviterTenderOutCheckRecord;
import com.ssy.lingxi.purchase.entity.tender.SubmitTenderOutCheckRecord;
import com.ssy.lingxi.purchase.service.tender.ITenderOutCheckRecordService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @menu: 招投标-外部状态流转管理
 * 外部状态流转管理类
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/3/1
 */
@RestController
@RequestMapping("/purchase/tenderOutCheckRecord")
public class TenderOutCheckRecordController extends BaseController {

    @Resource
    private ITenderOutCheckRecordService tenderOutCheckRecordService;

    /**
     * 查询招标详情的外部状态流转记录
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getInviteTenderOutCheckRecord", method = RequestMethod.GET)
    public Wrapper<List<TenderOutCheckRecordResponse>> getInviteTenderOutCheckRecord(@RequestParam("inviteTenderId") Long inviteTenderId) {
        List<InviterTenderOutCheckRecord> tenderOutCheckRecordList = tenderOutCheckRecordService.getInviteTenderOutCheckRecord(inviteTenderId);
        List<TenderOutCheckRecordResponse> result = tenderOutCheckRecordList.stream().map(tenderOutCheckRecord -> BeanUtil.copyProperties(tenderOutCheckRecord, TenderOutCheckRecordResponse.class)).collect(Collectors.toList());
        return Wrapper.success(result);
    }

    /**
     * 查询投标详情的外部状态流转记录
     * @param submitTenderId 投标id
     */
    @RequestMapping(value = "/getSubmitTenderOutCheckRecord", method = RequestMethod.GET)
    public Wrapper<List<SubmitTenderOutCheckRecordResponse>> getSubmitTenderOutCheckRecord(@RequestParam("submitTenderId") Long submitTenderId) {
        List<SubmitTenderOutCheckRecord> tenderOutCheckRecordList = tenderOutCheckRecordService.getSubmitTenderOutCheckRecord(submitTenderId);
        List<SubmitTenderOutCheckRecordResponse> result = tenderOutCheckRecordList.stream().map(tenderOutCheckRecord -> BeanUtil.copyProperties(tenderOutCheckRecord, SubmitTenderOutCheckRecordResponse.class)).collect(Collectors.toList());
        return Wrapper.success(result);
    }

    /**
     * 查询招标详情的外部状态流转记录--操作日志
     * @param inviteTenderId 招标id
     * @param startTime 开始时间
     * @param endTime 结束时间
     */
    @RequestMapping(value = "/getInviteTenderOutCheckRecordList", method = RequestMethod.GET)
    public Wrapper<PageData<TenderOutCheckRecordResponse>> getInviteTenderOutCheckRecordList(PageVO pageVO, @RequestParam(value = "inviteTenderId", required = false) Long inviteTenderId, @RequestParam(value = "startTime", required = false) Long startTime, @RequestParam(value = "endTime", required = false) Long endTime) {
        Page<InviterTenderOutCheckRecord> result = tenderOutCheckRecordService.getInviteTenderOutCheckRecordList(pageVO, inviteTenderId, startTime, endTime);
        List<TenderOutCheckRecordResponse> tenderOutCheckRecordList = result.getContent().stream().map(tenderOutCheckRecord -> BeanUtil.copyProperties(tenderOutCheckRecord, TenderOutCheckRecordResponse.class)).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), tenderOutCheckRecordList));
    }

}
